package edu.pku.sei.transformation.editor.controller.editparts.link;

import java.beans.PropertyChangeEvent;

import org.eclipse.draw2d.IFigure;
import org.eclipse.swt.SWT;

import edu.pku.sei.modeler.model.structure.MetaShapeElement;
import edu.pku.sei.transformation.editor.model.ModelPackage;
import edu.pku.sei.transformation.editor.model.TransformationFormalParameter;
import edu.pku.sei.transformation.editor.views.figures.ConnectionFigure;

public class TransformationFormalParameterEditpart extends
		TransformationLinkEditPart {
	public TransformationFormalParameterEditpart(MetaShapeElement conn) {
		super(conn);
	}

	@Override
	protected IFigure createFigure() {
		TransformationFormalParameter model = (TransformationFormalParameter) getLink()
				.getModelElement();
		ConnectionFigure figure = new ConnectionFigure(SWT.LINE_DASH);
		figure.setTargetDecoration(ConnectionFigure.ARROW);
		figure.setLabel("<<Formal Parameter>>",
				ConnectionFigure.CONNECTION_FIGURE_MIDDLE);
		// figure.setLabel(model.getName(),
		// ConnectionFigure.CONNECTION_FIGURE_TARGET);
		figure.setTooltipLabel(model.toString());
		return figure;
	}

	@Override
	protected void handlePropertyChanged(PropertyChangeEvent event) {
		String propertyName = event.getPropertyName();
		ConnectionFigure figure = (ConnectionFigure) getFigure();
		TransformationFormalParameter p = (TransformationFormalParameter) getLink()
				.getModelElement();
		if (ModelPackage.NAMEDELEMENT_NAME.equals(propertyName)) {
			figure.setLabel(event.getNewValue().toString(),
					ConnectionFigure.CONNECTION_FIGURE_TARGET);
			figure.setTooltipLabel(p.toString());
		} // else if (ModelPackage.)
		else
			super.handlePropertyChanged(event);
	}
}
